﻿using Conqueror.WP.Matchmaking;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Conqueror.WP.ViewModel.Matchmaking
{
    public class MatchmakingGamesViewModel : ViewModel
    {
        private string mapImageUrl;
        public string MapImageUrl { get { return mapImageUrl; } }

        private string title = "Just a test";
        public string Title { get { return title; } }

        private ObservableCollection<MatchmakingResultViewModel> results = new ObservableCollection<MatchmakingResultViewModel>();
        public ObservableCollection<MatchmakingResultViewModel> Results { get { return results; } }

        public string GenTitle()
        {
            switch(new Random().Next(5))
            {
                default:
                case 0:
                    return "HERE ARE SOME GAMES I FOUND";
                case 1:
                    return "WHAT DO YOU THINK OF THESE?";
                case 2:
                    return "I'VE FOUND A FEW GAMES FOR YOU";
                case 3:
                    return "HOW ABOUT ONE OF THESE?";
                case 4:
                    return "IS THIS WHAT YOU WERE LOOKING FOR?";
            }
        }

        public MatchmakingGamesViewModel()
        {
            MatchmakingViewModel vm = MatchmakingViewModel.Instance;
            mapImageUrl = vm.SelectedMap.LargeImage;
            title = GenTitle();

            Notify("Title");
            Notify("MapImageUrl");

            BuildResults();
        }

        private async Task BuildResults()
        {
            var list = await Matchmaker.FindMatches(MatchmakingViewModel.Instance.CreateMatchmakingParams());
            foreach(var g in list)
            {
                Results.Add(g);
            }
        }
    }
}
